package com.project.light.service.impl;

import com.project.light.entity.GroupInfo;
import com.project.light.mapper.GroupInfoMapper;
import com.project.light.service.GroupInfoService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;

@Service
public class GroupInfoServiceImpl implements GroupInfoService {

    @Resource
    private GroupInfoMapper groupInfoMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void insert(GroupInfo entity) throws Exception {
        groupInfoMapper.insertSelective(entity);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void update(GroupInfo entity) throws Exception {
        groupInfoMapper.updateByPrimaryKeySelective(entity);
    }

    @Override
    public GroupInfo getByGroupId(Integer groupId, String sysId) {
        Example example = new Example(GroupInfo.class);
        Example.Criteria c = example.createCriteria();
        c.andEqualTo("groupID", groupId);
        c.andEqualTo("sysId", sysId);
        List<GroupInfo> list = groupInfoMapper.selectByExample(example);
        return list.size() == 0 ? null : list.get(0);
    }
}
